<?php

//--------------------------------------------------------------------------------
// Parameters
//--------------------------------------------------------------------------------

// Database connection information
$dbhost="localhost";
$dbuser="jumping";
$dbpwd="jumping";
$dbname="jumping";

// Root URL of web site
$htdocs="http://berurier.homedns.org/jumping";
$url="$htdocs/jumping.php";
$imagesurl="$htdocs/webimages";
$thumbsurl="$htdocs/thumbs";

// Home directory to retrieve skins, configuration files...
$homedir="/library/www/jumping";
$webimagesdir = $homedir."/webimages";
$thumbsdir = $homedir."/thumbs";

// Name of skin (.xsl) file
$skin = "jumping.xsl";

// Time to live for a session (in seconds)
$sessionTTL = 10800;

// Size of thumbs
$webImagesWidth = 640;
$webImagesHeight = 480;
$webcanvas = "$homedir/canvas640.jpg";
$thumbsSize = 128;
$canvas = "$homedir/canvas128.jpg";


// Maximum number of images per category for a user 
$maxImagesPerCat = 10;

// Root element of .XML generated
$xmlroot = "jumping";


//--------------------------------------------------------------------------------
// Retrieve http POST or GET param
//--------------------------------------------------------------------------------
function getParam($name) {
  $val = $_GET{$name};
  if( $val == null ) 
    $val = $_POST{$name};
  debug("Parameter $name : $val");
  return $val;
}

//--------------------------------------------------------------------------------
// Validate a boolean
//--------------------------------------------------------------------------------
function validateBoolean($b) {
  if( $b == null ) return false;
  if( $b == true || $b == 1 || $b == 'true' ) return true;
  return false;
}

//--------------------------------------------------------------------------------
// Validate an integer
//--------------------------------------------------------------------------------
function validateInteger($i, $min, $max) {
  if( $i == null ) return $min;
  $i = (int)$i;
  if( $i >= $min && $i <= $max )
    return $i;
  return $min;
}

//--------------------------------------------------------------------------------
// Validate a string
//--------------------------------------------------------------------------------
function validateString($s, $len) {
  if( $s == null ) return "";
  if( strlen($s) > $len ) 
    $s = substr($s, 0, $len);
  return $s;
}

//--------------------------------------------------------------------------------
// Print out a debug string
//--------------------------------------------------------------------------------
function debug($msg) {
	global $debug;
	if( $debug )
		echo "<font size='1'>DEBUG: $msg<BR></font>";
}

function debugSQL($msg) {
	global $debugSQL;
	if( $debugSQL ) 
		echo "<font size='1'>DEBUG: [SQL] $msg<BR></font>";
}

//--------------------------------------------------------------------------------
// Generate unique UUID
//--------------------------------------------------------------------------------
function genUUID($len=16) {
	$pool = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	$pool .= "abcdefghijklmnopqrstuvwxyz";
	for( $i=0; $i<$len; $i++ ) {
		$sid .= substr($pool, (rand()%(strlen($pool))), 1);
	}
	return $sid;
}


?>
